package com.alan.mapper;

import com.alan.entity.Account;
import com.alan.entity.Word;
import com.alan.entity.Wordlist;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface VocabularyMapper {

    @Select("select * from db_wordlist")
    List<Wordlist> getAllList();

    @Select("SELECT w.* FROM db_word w\n" +
            "INNER JOIN list_word lw ON w.id = lw.wordId\n" +
            "WHERE lw.listId = #{listId}\n")
    List<Word> getWordsByListId(Integer listId);

    @Select("select * from db_word where id in (select wordId from user_revise where userId = #{userId})")
    List<Word> getReviseListByUserId(Integer userId);


    @Insert("INSERT INTO `schedule` (listId, learned, ndtolearn,userId)\n" +
            "VALUES (#{listId},0,#{wordNum},#{userId});")
    int insertSchedule(Integer userId,Integer listId,Integer wordNum);

    @Select("select * from db_wordlist where id = #{listId}")
    Wordlist getWordListById(Integer listId);

    //replace用法
    @Insert("REPLACE INTO `user_revise` (userId, wordId) VALUES (#{userId},#{wordId})")
    int insertReviseByUserId(Integer userId, Integer wordId);

    @Delete("DELETE from user_revise where userId = #{userId}")
    int clearReviseListByUserId(Integer userId);
}
